package kr.ac.hanyang.cs.jhpark;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;


public class main extends Activity implements OnClickListener {
	CastSkill castSkill								= null;
	String tmpSelectData							= null;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.castSkill								= new CastSkill(this);

        // register click listener
        Button btnRun								= (Button)findViewById(R.id.btn_Run);
        btnRun.setOnClickListener(this);
    }


    public void onClick(View view) {
    	String chkMesg;


    	// Get selected skill
        RadioGroup skillGrp							= (RadioGroup)findViewById(R.id.rGrp_Skills);
        RadioButton selectedSkill					= (RadioButton)findViewById(skillGrp.getCheckedRadioButtonId());
        
        switch (selectedSkill.getId()) {
        	// launch music application
        	case R.id.rBtn_AppLaunch:
        		chkMesg								= "External application launched";
        		//castSkill.launchApp("com.android.music");
        		Intent intent						= new Intent(this, SelectDialog.class);
        		startActivityForResult(intent, SelectDialog.SELECT_APP);
        		chkMesg								= tmpSelectData;
        		break;

        	// set screen off
        	case R.id.rBtn_ScreenOff:
        		chkMesg								= "Turning screen off";
        		castSkill.screenOff();
        		break;

        	// set wifi on
        	case R.id.rBtn_WifiOn:
        		chkMesg								= "Turning wifi on";
        		castSkill.setWifi(castSkill.STAT_ON);
        		break;

        	// set wifi off
        	case R.id.rBtn_WifiOff:
        		chkMesg								= "Turning wifi off";
        		castSkill.setWifi(castSkill.STAT_OFF);
        		break;

        		
        	// default
        	default:
        		chkMesg								= "Not implemented yet";
        }


        Toast.makeText(this, chkMesg, 3000).show();

        //*
        PkgInfo pkgInfo								= new PkgInfo(this);
        pkgInfo.setDebug(true);
        ArrayList<PkgInfo> pkgList					= pkgInfo.getPackageInfos();
        //*/

        //getAppList();
    }

    
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data){
		super.onActivityResult(requestCode, resultCode, data);

		if (resultCode == RESULT_OK) {
			if (requestCode == SelectDialog.SELECT_APP) { 
				tmpSelectData						= data.getStringExtra("Appname") +"||"+ data.getStringExtra("Package");
			}
		}

	}
    
    
}